package com.u.finance.call.controller;


import com.u.finance.call.entity.RepaymentSchedule;
import com.u.finance.call.service.IRepaymentScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alex Wu
 * @since 2025-03-31
 */
@RestController
@RequestMapping("/repayment-schedule")
public class RepaymentScheduleController {

    @Autowired
    private IRepaymentScheduleService repaymentScheduleService;

    @PostMapping
    public RepaymentSchedule createRepaymentSchedule(@RequestBody RepaymentSchedule repaymentSchedule) {
        repaymentScheduleService.save(repaymentSchedule);
        return repaymentSchedule;
    }

    @GetMapping("/{id}")
    public RepaymentSchedule getRepaymentSchedule(@PathVariable Long id) {
        return repaymentScheduleService.getById(id);
    }

    @PutMapping("/{id}")
    public RepaymentSchedule updateRepaymentSchedule(@PathVariable Long id, @RequestBody RepaymentSchedule repaymentSchedule) {
        repaymentScheduleService.updateById(repaymentSchedule);
        return repaymentSchedule;
    }

    @DeleteMapping("/{id}")
    public void deleteRepaymentSchedule(@PathVariable Long id) {
        repaymentScheduleService.removeById(id);
    }

}
